﻿<HTML>
<head>
<script type="text/javascript" src="../scripts/context.jsp"></script>
<script type="text/javascript" src="../scripts/jquery-1.4.2.js"></script>
<script type="text/javascript" src="../scripts/jquery.timer.js"></script>
</head>
<body>
<script type="text/javascript">
function __Timer__ (label, func){
	this.label = label;
	this.func = func;
	this.lastTime = new Date().getTime();
	this.expire = 5000;
	this.start = function(){
		this.stop();
		var THIS = this;
		$(this.label).everyTime('3s', function(){run(THIS);});
		var fn = function(){onEvent(THIS);};
		this.eventFunction = fn;
		$(document).mousemove(fn);
		$(document).keypress(fn);
		$(document).click(fn);
		show("start");
	}
	this.stop = function(){
		$(this.label).stopTime();
		var fn = this.eventFunction;
		if (typeof fn == 'function'){
			$(document).unbind('mousemove', fn);
			$(document).unbind('keypress', fn);
			$(document).unbind('click', fn);
			this.eventFunction = null;
		}
		show("stop");
	}
	
	function onEvent(timer){
		timer.lastTime = new Date().getTime();
		show("onEvent");
	}
	
	function run(timer) {
		var now = new Date().getTime();
		if (now - timer.lastTime > timer.expire){
			timer.lastTime = now;
			timer.func();
			show("call");
		} else {
			show("run " + (now - timer.lastTime));
		}
	}
	function show(text) {
		$("h2").html(text);
	}
}
$(function(){
	var Timer = new __Timer__("h1", function(){
		$("h1").text(new Date() + "");
	});
	Timer.start();
});

</script>
<script type="text/javascript">
$(function(){
//	$('h1').everyTime('3s',test);
//	$(document).mouseover(reset);
//	$(document).keypress(reset);
});
function test(){
	$(this).text(new Date() + "");
}
function stop() {
	$('h1').stopTime();
}
function reset() {
	$('h1').stopTime();
	$('h1').everyTime('3s',test);
}
</script>
<H1>Card Test Page</H1>
<h2></h2>
<p>You should see your Delphi 7 forms or controls embedded in the
form below.
<button value="stop" onclick="stop()">123</button>
</body>
</HTML>
